package com.fingard.dsp.bank.reqrespobj.batpayrec;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RequestBase;
import com.fingard.dsp.bank.reqrespobj.single.ReqQrySingle;
import com.fingard.text.StringHelper;
import com.fingard.xml.XmlTextReader;

import java.text.ParseException;
import java.util.Date;

public class ReqQryBatPayRec extends RequestBase{

	public String totalNum = "";
	public String totalAmt = "";
	public String reqBatchNO = "";//批次号，跟ATS数据库字段保持一致
	public String ownAct = "";
	public String ownArea = "";
	public String bgnDate = "";
	public String useType = "";
	public String ownBankCode = "";
	public String sameBnk = "";
	public String payState;
	public String officePurpose;//保险公司指定商户订单号
	public String circMchNo;//保险公司指定商户订单号
	public String certType;
	public String certNum;
	public String authCode;
	public String insuPolicyNum;
	public String memo;
    /**
     * 订单号
     */
    public String orderNo;
	private XmlTextReader xmlReader;
	
	public ReqQryBatPayRec(ReqQrySingle p_req1944) throws Exception{
		XmlTextReader tmpReader = new XmlTextReader(p_req1944.getOriReqXml());
		reqHeader = p_req1944.reqHeader.clone();
		init(tmpReader, reqHeader);
		totalNum = "1";
		totalAmt = xmlReader.getSimpleText("PayAmount");
		reqBatchNO = xmlReader.getSimpleText("ReqSeqID");
        orderNo = xmlReader.getSimpleTextNotNull("OrderNumber");
	}
	public ReqQryBatPayRec(XmlTextReader p_xmlReader, ReqRespHeader p_header) throws Exception{
		init(p_xmlReader, p_header);
	}
	
	public void init(XmlTextReader p_xmlReader, ReqRespHeader p_header) throws Exception{
		reqHeader = p_header;
		xmlReader = p_xmlReader;
		totalNum = xmlReader.getSimpleText("TotalNum");
		totalAmt = xmlReader.getSimpleText("TotalAmt");
		reqBatchNO = xmlReader.getSimpleText("ReqSeqID");
        orderNo = xmlReader.getSimpleTextNotNull("OrderNumber");
		if(p_header.transType.equals("1998")){
			ownAct = xmlReader.getSimpleText("PayAct");
			ownArea = xmlReader.getSimpleText("PayArea");
			ownBankCode = xmlReader.getSimpleText("PayBankCode");
			sameBnk = xmlReader.getSimpleText("SameBnk");
		}
		else if(p_header.transType.equals("9198")){
			ownAct = xmlReader.getSimpleText("RecAct");
			ownArea = xmlReader.getSimpleText("RecArea");
			ownBankCode = xmlReader.getSimpleText("RecBankCode");
		}
		bgnDate = xmlReader.getSimpleText("BgnDate");
		
		useType = xmlReader.getSimpleTextNotNull("OfficePurpose");
		if(useType.length() == 0){
			useType = xmlReader.getSimpleTextNotNull("UseType");
		}
		
		payState = xmlReader.getSimpleTextNotNull("PayState");
		if(StringHelper.isNullOrEmpty(payState)){
			payState = "5";
		}
		officePurpose = xmlReader.getSimpleTextNotNull("OfficePurpose");
		circMchNo = xmlReader.getSimpleTextNotNull("CircMchNo");
		certType = xmlReader.getSimpleTextNotNull("CertType");
		certNum = xmlReader.getSimpleTextNotNull("CertNum");
		authCode = xmlReader.getSimpleTextNotNull("AuthCode");
		insuPolicyNum = xmlReader.getSimpleTextNotNull("InsuPolicyNum");
		memo = xmlReader.getSimpleTextNotNull("Memo");
	}
	
	public Date getBgnDateTime() throws ParseException{
		return Format.DateTimeFormat.parse(bgnDate);
	}

	public String getOriReqXml(){
		return xmlReader.getOriXmlString();
	}
}
